package cn.intotw.rdcj.task.spiders.client;

import java.net.URI;
import java.util.concurrent.ConcurrentHashMap;


/**
 * Created by Chenxiang
 *
 * @generator: IntelliJ IDEA
 * @description: NettyClient工厂类
 * @project: rdcj
 * @package: cn.intotw.rdcj.task.spiders.client
 * @date: 2020年07月28日 10时13分
 */
public class NettyClientGroup {
    private static final ConcurrentHashMap<String,NettySpidersClient> CLIENTS=new ConcurrentHashMap<>();
    public static NettySpidersClient getNettyClient(URI uri){
        NettySpidersClient nettySpidersClient = CLIENTS.get(uri.getHost());
        if(nettySpidersClient!=null){
            return nettySpidersClient;
        }else {
            NettySpidersClient newClient = new NettySpidersClient(uri);
            NettySpidersClient oldClient = CLIENTS.putIfAbsent(uri.getHost(), newClient);
            if(oldClient==null){
                return newClient;
            }else {
                return oldClient;
            }
        }
    }
}
